<template>
  <a-modal
    :visible="upLoadEditShow"
    width="40vw"
    title="上传文件"
    title-align="start"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-form
      ref="formRef"
      :model="uploadForm"
      :rules="formRules"
      auto-label-width
      layout="vertical"
    >
      <!-- 选商方式确认子表单新增+编辑 -->
      <a-row :gutter="24">
        <a-col :span="12">
          <a-form-item field="planListNo" label="计划编号：">
            <a-input v-model="uploadForm.planListNo" disabled placeholder="" />
          </a-form-item>
          <a-form-item field="mdsItemCode" label="物料编号：">
            <inputModal
              v-model="uploadForm.mdsItemCode"
              :label-value="uploadForm.mdsItemCode"
              :value-name="'materialCode'"
              :title="'物料选择'"
              :type="'materialCode'"
              @handle-ok="selectMaterial"
            />
            <!-- <a-input v-model="uploadForm.mdsItemCode" placeholder="" /> -->
          </a-form-item>
          <a-form-item field="tndofrFileNo" label="招标文件编号：">
            <a-input v-model="uploadForm.tndofrFileNo" placeholder="" />
          </a-form-item>
          <a-form-item field="pmsMajorCatogoryCode" label="采购类型">
            <dict-select
              v-model="uploadForm.pmsMajorCatogoryCode"
              allow-clear
              dict-type="procurementType"
              placeholder="请选择"
            ></dict-select>
          </a-form-item>
          <a-form-item field="actTenderDate" label="实际招标时间：">
            <a-date-picker
              v-model="uploadForm.actTenderDate"
              :allow-clear="true"
              style="width: 100%"
              value-format="YYYY-MM-DD"
            />
          </a-form-item>
          <a-form-item field="vendorBiddingDate" label="竞标时间：">
            <a-date-picker
              v-model="uploadForm.vendorBiddingDate"
              :allow-clear="true"
              style="width: 100%"
              value-format="YYYY-MM-DD"
            />
          </a-form-item>
          <a-form-item field="bidNoticeSendTime" label="中标通知书发出时间：">
            <a-date-picker
              v-model="uploadForm.bidNoticeSendTime"
              :allow-clear="true"
              style="width: 100%"
              value-format="YYYY-MM-DD"
            />
          </a-form-item>
          <a-form-item field="tenderDutyName" label="招标负责人：">
            <!-- <inputModal
                    v-model="uploadForm.tenderDutyName"
                    :label-value="uploadForm.tenderDutyName"
                    :value-name="'name'"
                    :title="'招标负责人：'"
                    :type="'supplyName'"
                  /> -->
            <searchItemUser
              v-model="uploadForm.tenderDutyName"
              v-model:name="uploadForm.tenderDutyName"
              :title="'招标负责人：'"
            />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="tenderTypeCode" label="招标方式：">
            <dict-select
              v-model="uploadForm.tenderTypeCode"
              allow-clear
              dict-type="biddingMethod"
              placeholder="请选择"
            ></dict-select>
          </a-form-item>
          <a-form-item field="mdsItemName" label="物料名称：">
            <a-input v-model="uploadForm.mdsItemName" placeholder="" />
          </a-form-item>
          <a-form-item field="tndofrFileName" label="招标文件名称：">
            <a-input v-model="uploadForm.tndofrFileName" placeholder="" />
          </a-form-item>
          <a-form-item field="planTenderDate" label="预计招标时间：">
            <a-date-picker
              v-model="uploadForm.planTenderDate"
              :allow-clear="true"
              style="width: 100%"
              value-format="YYYY-MM-DD"
            />
          </a-form-item>
          <a-form-item field="vendorTenderEndDate" label="供应商投标结束时间：">
            <a-date-picker
              v-model="uploadForm.vendorTenderEndDate"
              :allow-clear="true"
              style="width: 100%"
              value-format="YYYY-MM-DD"
            />
          </a-form-item>
          <a-form-item field="vendorBiddingAddress" label="竞标地点：">
            <a-input v-model="uploadForm.vendorBiddingAddress" placeholder="" />
          </a-form-item>
          <a-form-item field="tenderDeptName" label="招标负责人部门：">
            <a-input v-model="uploadForm.tenderDeptName" placeholder="" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-item field="notes" label="描述：">
            <a-input v-model="uploadForm.notes" placeholder="" />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </a-modal>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import dictSelect from '@/common/components/dict-select/index.vue';
  import searchItemUser from '@/common/components/search-modal/user.vue';
  import {
    getTenderByPlanListNo,
    getTenderByPlanListNo2,
  } from '@/api/supplier/selective-quotient';
  import { Message } from '@arco-design/web-vue';
  import inputModal from '@/common/components/search-modal/input-modal.vue';

  const formRules = ref({
    planListNo: [
      {
        required: true,
        message: '请输入计划编号',
        trigger: 'change',
      },
    ],
    tndofrFileNo: [
      {
        required: true,
        message: '请输入招标文件编号',
        trigger: 'change',
      },
    ],
    pmsMajorCatogoryCode: [
      {
        required: true,
        message: '请选择采购类型',
        trigger: 'change',
      },
    ],
    tenderTypeCode: [
      {
        required: true,
        message: '请输入招标方式',
        trigger: 'change',
      },
    ],
  });
  const upLoadEditShow = ref(false);
  const uploadForm = ref({
    planListNo: '',
    mdsItemCode: '',
    tndofrFileNo: '',
    pmsMajorCatogoryCode: '',
    actTenderDate: '',
    vendorBiddingDate: '',
    bidNoticeSendTime: '',
    tenderDutyName: '',
    tenderTypeCode: '',
    mdsItemName: '',
    tndofrFileName: '',
    planTenderDate: '',
    vendorTenderEndDate: '',
    vendorBiddingAddress: '',
    tenderDeptName: '',
    notes: '',
  });
  const selectMaterial = (val) => {
    uploadForm.value.mdsItemName = val.materialName;
  };
  const formRef = ref();
  const emit = defineEmits(['handleCancel']);
  const init = async (val) => {
    upLoadEditShow.value = true;
    const { data } = await getTenderByPlanListNo(val.planListNo);
    Object.assign(uploadForm.value, data);
    uploadForm.value.planListNo = val.planListNo;
  };
  const handleOk = async () => {
    const val = await formRef.value.validate();
    if (val) {
      return;
    }
    const { data } = await getTenderByPlanListNo2({
      ...uploadForm.value,
    });
    if (data) {
      Message.success('上传成功');
      handleCancel();
    }
  };
  const handleCancel = () => {
    upLoadEditShow.value = false;
    emit('handleCancel');
  };
  defineExpose({ init });
</script>
